package com.zhitong.money.mapper;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author: Andy Zhang
 * @Description:
 * @Date: 14:25 2021/2/1
 * @Company: wisecard
 */
@Mapper
public interface UserRolemapper {

    @Insert("insert into user_role values(#{uid},#{rid})")
    public void add(String uid,String rid);

    @Delete("delete from user_role where uid = #{uid}")
    public void deleteByUid(String uid);

    @Delete("delete from user_role where rid = #{rid}")
    public void deleteByRid(String rid);

    @Delete({
            "<script>",
            "delete from user_role",
            "where rid in",
            "<foreach item='item' collection='rids' separator=',' open='(' close=')' index=''>",
            "#{item}",
            "</foreach>",
            "</script>"
    })
    public void deleteByRids(List<String> rids);

    @Delete({
            "<script>",
            "delete from user_role",
            "where uid in",
            "<foreach item='item' collection='uids' separator=',' open='(' close=')' index=''>",
            "#{item}",
            "</foreach>",
            "</script>"
    })
    public void deleteByUids(List<String> uids);

    @Select("select count(*) from user_role where rid = #{rid}")
    public int countByRid(String rid);

    @Select( {
            "<script>",
            "select count(*) from user_role",
            "where rid in",
            "<foreach item='item' collection='rids' separator=',' open='(' close=')' index=''>",
            "#{item}",
            "</foreach>",
            "</script>"
    })
    public int countByRids(List<String> rids);
}
